﻿using System.Drawing;

using Microsoft.AspNetCore.Mvc;

namespace PageOffice6_Net_Core.Controllers.SetExcelCellBorder
{
    public class SetExcelCellBorderController : Controller
    {
        public IActionResult Excel()
        {
            PageOfficeNetCore.PageOfficeCtrl poCtrl = new PageOfficeNetCore.PageOfficeCtrl(Request);

            PageOfficeNetCore.Excel.WorkbookWriter wb = new PageOfficeNetCore.Excel.WorkbookWriter();
            PageOfficeNetCore.Excel.SheetWriter sheet = wb.OpenSheet("Sheet1");
            // 设置背景
            PageOfficeNetCore.Excel.ExcelTableWriter backGroundTable = sheet.OpenTable("A1:P200");
            //设置表格边框样式
            backGroundTable.Border.LineColor = Color.White;

            // 设置单元格边框样式
            PageOfficeNetCore.Excel.ExcelBorder C4Border = sheet.OpenTable("C4:C4").Border;
            C4Border.Weight = PageOfficeNetCore.Excel.XlBorderWeight.xlThick;
            C4Border.LineColor = Color.Yellow;
            C4Border.BorderType = PageOfficeNetCore.Excel.XlBorderType.xlAllEdges;

            // 设置单元格边框样式
            PageOfficeNetCore.Excel.ExcelBorder B6Border = sheet.OpenTable("B6:B6").Border;
            B6Border.Weight = PageOfficeNetCore.Excel.XlBorderWeight.xlHairline;
            B6Border.LineColor = Color.Purple;
            B6Border.LineStyle = PageOfficeNetCore.Excel.XlBorderLineStyle.xlSlantDashDot;
            B6Border.BorderType = PageOfficeNetCore.Excel.XlBorderType.xlAllEdges;

            //设置表格边框样式
            PageOfficeNetCore.Excel.ExcelTableWriter titleTable = sheet.OpenTable("B4:F5");
            titleTable.Border.Weight = PageOfficeNetCore.Excel.XlBorderWeight.xlThick;
            titleTable.Border.LineColor = Color.FromArgb(0, 128, 128);
            titleTable.Border.BorderType = PageOfficeNetCore.Excel.XlBorderType.xlAllEdges;

            //设置表格边框样式
            PageOfficeNetCore.Excel.ExcelTableWriter bodyTable2 = sheet.OpenTable("B6:F15");
            bodyTable2.Border.Weight = PageOfficeNetCore.Excel.XlBorderWeight.xlThick;
            bodyTable2.Border.LineColor = Color.FromArgb(0, 128, 128);
            bodyTable2.Border.BorderType = PageOfficeNetCore.Excel.XlBorderType.xlAllEdges;

            poCtrl.SetWriter(wb);// 不要忘记此句代码

            //打开Excel文档
            poCtrl.WebOpen("doc/test.xls", PageOfficeNetCore.OpenModeType.xlsNormalEdit, "tom");
            ViewBag.poCtrl = poCtrl.GetHtml();
            return View();
        }

    }
}